package jpb.util.load.excel;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;

/**
 * Created by haol on 2017/4/17.
 */
public class ExcelCellStyle {
        private HSSFWorkbook workbook;

        public ExcelCellStyle(HSSFWorkbook workbook) {
                this.workbook = workbook;
        }

        public HSSFCellStyle headStyle() {
                HSSFFont font = workbook.createFont();
                font.setColor(HSSFFont.COLOR_RED);
                font.setFontHeightInPoints((short) 12);

                HSSFCellStyle cellStyle = workbook.createCellStyle();
                cellStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
                cellStyle.setFillBackgroundColor(HSSFColor.YELLOW.index);
                cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
                cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
                cellStyle.setFont(font);

                return cellStyle;
        }

        public HSSFCellStyle alignStyle() {
                HSSFFont font = workbook.createFont();


                HSSFCellStyle cellStyle = workbook.createCellStyle();

                cellStyle.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER);
                cellStyle.setFillForegroundColor(HSSFColor.BROWN.index);
                cellStyle.setFillBackgroundColor(HSSFColor.BROWN.index);
                cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
                cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
                cellStyle.setFont(font);
                return cellStyle;
        }

        public HSSFCellStyle textStyle() {

                HSSFCellStyle cellStyle = workbook.createCellStyle();
                HSSFDataFormat format = workbook.createDataFormat();
                cellStyle.setDataFormat(format.getFormat("@"));
                return cellStyle;
        }

        public HSSFSheet setLotCell(HSSFSheet sheet,int firstRow, int lastRow, int firstCol, int lastCol,HSSFCellStyle style){
                for (int i = firstRow;i<lastRow;i++){
                        HSSFRow row = sheet.createRow(i);
                        for (int j = firstCol;j<lastCol;j++){
                                HSSFCell cell =row.createCell(j);
                                cell.setCellStyle(style);
                        }
                }
                return sheet;
        }
}
